<?php
namespace app\admin\controller;

use app\common\builder\ZBuilder;
use app\admin\model\Wxapp as WxappModel;
use think\Image;
use think\File;
use think\facade\Hook;
use think\Db;
use think\facade\Env;
class Wxapp extends Admin
{
     public function index()
    {
        // 查询
        $map = $this->getMap();
        // 数据列表
        $data_list = WxappModel::where($map)->order('id desc')->paginate();
        foreach($data_list as $k=>$row){
            $data_list[$k]['wechat_img'] = getImgUrl($row['wechat_img']);
        }
        $fields = [
            ['hidden','id'],
            ['text','title','小程序名称'],
            ['text','intention_title','初衷标题'],
            ['ueditor','intention','初衷'],
            ['text','wechat_num','客服微信号'],
            ['image','wechat_img','客服微信号二维码'],
            ['text','rules_title','群规标题'],
            ['ueditor','rules','群规'],
            ['text','skill_title','技巧标题'],
            ['ueditor','skill','技巧'],
            ['radio','status','状态','', ['禁用', '启用'], 1],
        ];
        return ZBuilder::make('table')
        ->setSearch(['name' => '标题']) // 设置搜索框
        ->setPageTitle('小程序管理')
        ->autoAdd($fields,'','','addtime') // 添加新增按钮
        ->autoEdit($fields,'','','mdtime') // 添加编辑按钮
        ->addColumns([ // 批量添加数据列
            ['id', 'ID'],
            ['title', '小程序名称'],
            ['wechat_num', '客服微信号'],
            ['wechat_img', '微信二维码'],
            ['addtime', '添加时间', 'datetime'],
            ['status', '状态', 'switch'],
            ['right_button', '操作', 'btn']
        ])
        ->addTopButtons('enable,disable,delete') // 批量添加顶部按钮
        ->addRightButtons('delete') // 批量添加右侧按钮
        ->setRowList($data_list) // 设置表格数据
        ->fetch(); // 渲染模板
    }
}